#pragma once
#include <iostream>
#include "Protocol.hpp"
class Calculator
{
public:
    Calculator() 
    {
    }
    ~Calculator()
    {

    }
    std::shared_ptr<Response> Cal(std::shared_ptr<Request> req)
    {
        auto res = Factory::BuildResponse();
        switch (req->_oper) {
        case '+':
            res->_result = req->_x + req->_y;
            res->_code = 0;

            break;
        case '-':
            res->_result = req->_x - req->_y;
            res->_code = 0;

            break;
        case '*':
            res->_result = req->_x * req->_y;
            res->_code = 0;

            break;
        case '/':
            if(req->_y == 0) {
                res->_code = 1;
                res->_result = 0;
            } else {
                res->_code = 0;
                res->_result = req->_x / req->_y;
            }
            break;
        default:
            res->_code = 2;  // 无效操作符
            break;
        }
        return res;
    }
};